package cn.lingyangwl.agile.member;

import cn.lingyangwl.agile.member.model.rqrs.user.MemberUserRegisterReq;
import cn.lingyangwl.agile.member.model.rqrs.user.MemberUserResp;
import cn.lingyangwl.agile.member.model.rqrs.user.MemberUserUpdateReq;
import cn.lingyangwl.framework.core.response.Resp;
import cn.lingyangwl.framework.core.response.RetOps;
import cn.lingyangwl.framework.tool.core.exception.BizException;
import com.alibaba.cloud.nacos.NacosServiceAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author shenguangyang
 */
@Service
@ConditionalOnClass({FeignAutoConfiguration.class, NacosServiceAutoConfiguration.class})
public class MemberApiCloudImpl implements MemberApi {
    @Resource
    private MemberRemote service;

    @Override
    public MemberUserResp registerUserIfAbsent(MemberUserRegisterReq req) {
        Resp<MemberUserResp> resp = service.registerUserIfAbsent(req);
        RetOps.of(resp).assertSuccess(e -> new BizException(e.getCode(), e.getMsg()));
        return resp.getData();
    }

    @Override
    public void updateUser(MemberUserUpdateReq req) {
        Resp<?> resp = service.updateUser(req);
        RetOps.of(resp).assertSuccess(e -> new BizException(e.getCode(), e.getMsg()));
    }
}
